// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
import * as vscode from 'vscode';
import * as service from './service';
import * as ExcelUtils from './utils/ExcelUtils';
import * as SQLUtils from './utils/SQLUtils';
import { ExtensionCommandsProvider } from './utils/ExtensionCommandsProvider';

export function activate(context: vscode.ExtensionContext) {
	console.log('Congratulations, your extension "vscode-text-util" is now active!');

	// 检查重复
	context.subscriptions.push(
		vscode.commands.registerCommand('vscodeTextUtil.checkDuplicate', () => {
			service.checkDuplicate();
		})
	);

	// 生成模板
	context.subscriptions.push(
		vscode.commands.registerCommand('vscodeTextUtil.genTemplate', () => {
			service.genTemplate();
		})
	);

	// 添加其他维度
	context.subscriptions.push(
		vscode.commands.registerCommand('vscodeTextUtil.addOtherDims', () => {
			service.addOtherDims();
		})
	);

	// 生成SQL
	context.subscriptions.push(
		vscode.commands.registerCommand('vscodeTextUtil.genSQL', () => {
			service.genSQL();
		})
	);

	// 将excel字母列替换为数字
	context.subscriptions.push(
		vscode.commands.registerCommand('vscodeTextUtil.excelColumnToNumber', () => {
			service.replaceSelectedText();
		})
	);

	// 注册复制选中文本到剪贴板的命令
	context.subscriptions.push(
		vscode.commands.registerCommand('vscodeTextUtil.descriptionToSqlCondition', async () => {
			service.descriptionToSqlCondition();
		})
	);

	// 将SQL复制到剪切板
	context.subscriptions.push(
		vscode.commands.registerCommand('vscodeTextUtil.copySQL', async () => {
			service.copySQL();
		})
	);

	// 注册树形视图
	context.subscriptions.push(
		vscode.window.createTreeView('vscodeTextUtil.commandView', {
			treeDataProvider: new ExtensionCommandsProvider(context)
		})
	);

	// 注册执行命令
	context.subscriptions.push(
		vscode.commands.registerCommand('vscodeTextUtil.executeCommand', (commandId: string) => {
			vscode.commands.executeCommand(commandId)
				.then(undefined, err => {
					vscode.window.showErrorMessage(`执行命令失败: ${err}`);
				});
		})
	);
}

// This method is called when your extension is deactivated
export function deactivate() { }
